package com.cskaoyan.controller;


import com.cskaoyan.bean.Coupon;
import com.cskaoyan.bean.CouponUser;
import com.cskaoyan.bean.vo.AdminAdForListDataBean;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.AdminCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/coupon")
public class AdminCouponController {

    @Autowired
    AdminCouponService couponService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page, Integer limit, String name, String sort, String order, Short type, Short status) {
        AdminAdForListDataBean<Coupon> result = couponService.queryCoupon(page, limit, name, sort, order,type, status);

        return BaseRespVo.ok(result);
    }

    @RequestMapping("read")
    public BaseRespVo read(Integer id) {
        Coupon result = couponService.queryCouponById(id);

        return BaseRespVo.ok(result);
    }
    @RequestMapping("listuser")
    public BaseRespVo listUser(Integer page, Integer limit, Integer couponId, Integer userId, Short status, String sort, String order){
        AdminAdForListDataBean<CouponUser> result = couponService.queryCouponUsers(page, limit, couponId, userId, status, sort, order);
        return BaseRespVo.ok(result);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Coupon coupon) {
        Integer result = couponService.AddCoupon(coupon);
        return result == 1 ? BaseRespVo.ok(coupon) : BaseRespVo.fail();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Coupon coupon) {
        Integer result = couponService.deleteCoupon(coupon);
        return result == 1 ? BaseRespVo.ok() : BaseRespVo.fail();
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Coupon coupon) {
        Integer result = couponService.updateCoupon(coupon);

        return result == 1 ? BaseRespVo.ok(coupon) : BaseRespVo.fail();

    }
}
